public class RecursiveAlgorithm {
    public static void main(String[] args) {

        //一、求1-100之间的和，100+99+98+......+2+1
        //1~100的和=100+1~99的和
        //1~99的和=99+1~98的和
        //......
        //1~2的和=2+1~2的和
        //1~1=1（出口）
        System.out.println(getSum(100));//5050

        System.out.println("-----------------------------");

        //二、求5！
        //5!=5*4!
        //4!=4*3!
        //......
        //1!=1（出口）
        System.out.println(getFactorialRecursion(5));//120

    }

    public static int getSum(int num){
        if(num==1){
            return 1;
        }
        return num=num+getSum(num-1);
    }

    public static int getFactorialRecursion(int num){
        if(num==1){
            return 1;
        }
        return num*getFactorialRecursion(num-1);
    }

}
